import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:seedfour/app/constants.dart';

import 'logic.dart';

class SplashPage extends StatelessWidget {
  SplashPage({Key? key}) : super(key: key);

  final logic = Get.find<SplashLogic>();

  @override
  Widget build(BuildContext context) {
    return Obx(
      () => logic.showPrivacyDialog.value
          ? showPrivacy(context)
          : Container(
              alignment: Alignment.bottomCenter,
              padding: EdgeInsets.only(bottom: kSpaceHuge),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  SvgPicture.asset(
                    'assets/images/logo.svg',
                    width: kIconSizeLarge,
                    height: kIconSizeLarge,
                  ),
                  SizedBox(width: kSpaceSmall),
                  Text(
                    '师付',
                    style: TextStyle(
                      fontWeight: FontWeight.w700,
                      fontSize: kFontSizeBig + kFontSizeTiny,
                    ),
                  )
                ],
              ),
            ),
    );
  }

  // 隐私政策弹窗
  Widget showPrivacy(BuildContext context) {
    final ColorScheme colorScheme = Theme.of(context).colorScheme;

    return AlertDialog(
      title: const Text('隐私政策'),
      content: RichText(
        text: TextSpan(children: [
          TextSpan(
            text: '欢迎使用”师付“，我们非常重视您的个人信息和隐私保护。在您使用“师付”服务之前，请仔细阅读',
            style: TextStyle(
              fontSize: kFontSizeSmall,
              color: Colors.black87,
            ),
          ),
          TextSpan(
            text: '《用户协议》',
            style: TextStyle(
              fontSize: kFontSizeSmall,
              color: colorScheme.primary,
              decoration: TextDecoration.underline,
            ),
            recognizer: TapGestureRecognizer()
              ..onTap = () => logic.onClickAgreement(),
          ),
          TextSpan(
            text: ' 和 ',
            style: TextStyle(
              fontSize: kFontSizeSmall,
              color: Colors.black87,
            ),
          ),
          TextSpan(
            text: '《隐私政策》',
            style: TextStyle(
              fontSize: kFontSizeSmall,
              color: colorScheme.primary,
              decoration: TextDecoration.underline,
            ),
            recognizer: TapGestureRecognizer()
              ..onTap = () => logic.onClickPrivacy(),
          ),
          TextSpan(
            text: '我们将按照您同意的条款使用您的个人信息，以便为您提供服务。',
            style: TextStyle(
              fontSize: kFontSizeSmall,
              color: Colors.black87,
            ),
          ),
          TextSpan(
            text: '\n\n\n如您同意此政策，请点击“同意”并开始使用我们的产品和服务，我们尽全力保护您的个人信息安全。',
            style: TextStyle(
              fontSize: kFontSizeMini,
              color: Colors.grey,
            ),
          ),
        ]),
      ),
      actions: <Widget>[
        TextButton(
          child: const Text('不同意'),
          onPressed: () {
            logic.onPrivacyDisagreed();
          },
        ),
        TextButton(
          child: const Text('同意'),
          onPressed: () {
            logic.onPrivacyAgreed();
          },
        ),
      ],
    );
  }
}
